<template>
	<view>
		<view class="items title" style="display: flex;flex-direction: column;align-items: center;justify-items: center;padding-top: 80upx;">
			
			<avatar selWidth="240px" selHeight="400upx" @upload="myUpload" :avatarSrc="url"
				avatarStyle="width: 120upx; height: 120upx;border-radius:50%;">
				
			</avatar>
			<view style="color: #0056AE;font-size: 30upx;">点击更换头像</view>
		</view>
		<view class="list">
			<view class="items" style="display: flex;justify-content: flex-start;" @click="toming">
				<view class="list-z">
					<view class="" style="display: flex;justify-content: flex-start;">
						<text style="font-size: 26upx;color:#666666;">姓名</text>
						<!-- <text style="color: red;">*</text> -->
					</view>
					<view style="color: #333333;font-size: 30upx;">
						<input type="text" v-model="user_name" placeholder="请输入姓名" style="font-size: 30upx;" disabled="false"/>
					</view>
				</view>
						<image src="../../../static/tuo.png" mode="" style="width: 28upx;height: 28upx;padding-right: 0upx;"></image>
		
			</view>
		</view>
		<view class="list">
			<view class="items" style="display: flex;justify-content: flex-start;" @click="tome">
				<view class="list-z">
					<view class="" style="display: flex;justify-content: flex-start;">
						<text style="font-size: 26upx;color:#666666;">个人简介</text>
						<!-- <text style="color: red;">*</text> -->
					</view>
					<view style="color: #333333;font-size: 30upx;">
						<!-- <textarea name="" id="" cols="30" rows="10" v-model="jianjie" placeholder="介绍一下你自己" style="font-size: 30upx;"></textarea> -->
						<input type="text" v-model="jianjie" placeholder="介绍一下你自己" v-if="jianjie==''">
						<text v-else>{{jianjie}}</text>
					</view>
				</view>
						<image src="../../../static/tuo.png" mode="" style="width: 28upx;height: 28upx;padding-right: 0upx;"></image>
		
			</view>
		</view>
		<view class="list">
			<text style="color: #999;font-size: 26upx;">性别</text>
			<picker @change="bindPickerChanged" :range="arrays">
				<view>
					<label class="pr38">{{arrays[indexd]}}</label>
					<image src="../../../static/tuo.png" mode=""
						style="width: 30upx;height: 30upx;padding-right: 0upx;"></image>
				</view>
			</picker>
		</view>
		<view class="list">
			<text style="color: #999;font-size: 26upx;">出生年月</text>
			<view style="color: #333333;font-size: 30upx;" @click="showPop">
				<input type="text" placeholder="请选择出生年月" style="font-size: 30upx;" disabled="true" v-model="shijian" />
					<image src="../../../static/tuo.png" mode=""
						style="width: 30upx;height: 30upx;padding-right: 0upx;"></image>
			</view>
			<min-picker :endTime="endTime" :startTime="startTime" @cancel="cancel" @sure="sure" :show="show" heightRpx="500">
			</min-picker>
		</view>
	</view>
</template>

<script>
	import avatar from "@/components/yq-avatar/yq-avatar.vue";
	import gppDatePicker from "@/components/gpp-datePicker/gpp-datePicker.vue"
	import {
		pathToBase64,
		base64ToPath
	} from '@/components/mmmm-image-tools/index.js'
	export default {
		data() {
			return {
				url: "../../../static/tianjia.png",
				user_name: '',
				arrays: ['选择性别', '男', '女'],
				array: ['选择学历'],
				indexd: 0,
				sex: '',
				startDate: "1980-01-01",
				jianjie:'',
				xingbie:'',
				endDate: "2023-01-01",
				pickerDate: '1988-01-01',
				startDated: "1960-01-01",
				endDated: "2023-01-01",
				pickerDated: '2000-01-01',
				startTime: [1960, 1, 20],
				startTimed: [1960, 1, 20],
				endTime: 2022,
				endTimed: 2022,
				show: false,
				showd: false,
				userinfo: {},
				userinfos: {},
				school_name: '',
				isxue: false,
				leftList: [],
				school_professional: '',
				xuelist: [],
				indexw: 0,
				zhenImg: '',
				edu_id: '',
				useid: '',
				shijian: "",
				workshijian:'',
			}
		},
		components:{
			avatar
		},
		onLoad(option) {
			this.useid = option.useid
			uni.request({
				url: 'https://dsx.cdzer.com/api/MemberInfo/getuserinfo', //仅为示例，并非真实接口地址。
				method: 'POST',
				data: {
					uid: option.useid
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded',
				},
				success: (res) => {
					console.log(res, "sdadasdasdas")
					this.userinfo =  res.data.data
					this.user_name = res.data.data.user_name
					this.jianjie = res.data.data.evaluation
					this.shijian = res.data.data.birth
					this.indexd = res.data.data.sex
					if(res.data.data.sex == 1){
						this.xingbie = "男"
					}else if(res.data.data.sex == 2){
						this.xingbie = "女"
					}else{
						this.xingbie = "选择性别"
					}
					// this.imageValue.push(res.data.data.resume_url)  
					if(res.data.data.headimgurl){
						this.url = res.data.data.headimgurl
					}else{
						this.url = "../../../static/tianjia.png"
					}
					
				}
			});
		},
		methods: {
			tome(){
				uni.navigateTo({
					url:`./myjianjie?useid=${this.userinfo.id}`
				})
			},
			toming(){
				uni.navigateTo({
					url:`./mingzi?name=${this.user_name}`
				})
			},
			
			bindPickerChanged: function(e) { //改变的事件名
				this.indexd = e.target.value //将数组改变索引赋给定义的index变量
				this.sex = e.target.value
				console.log(e, "选择学历")
				var data ={
					field_name:'sex',
					field_data:this.sex 
				}
				this.$http.useben(data).then(res => {
					if (res.status == 200) {
						console.log(res, "保存资料")
						this.$hideLoading()
						uni.showToast({
							title: res.mess
						})

					} else {
						uni.showToast({
							title: res.mess,
							icon: 'none'
						})
					}
				})
			},
			cancel() {
				this.show = false
			},
			sure(e) {
				console.log(e) // 返回的结果
				this.shijian = e.a + '-' + e.b + '-' + e.c
				this.show = false
				var data ={
					field_name:'birth',
					field_data:this.shijian
				}
				this.$http.useben(data).then(res => {
					if (res.status == 200) {
						console.log(res, "保存资料")
						this.$hideLoading()
						uni.showToast({
							title: res.mess
						})
					} else {
						uni.showToast({
							title: res.mess,
							icon: 'none'
						})
					}
				})
			},
			showPop() {
				this.show = true
			},
			myUpload(rsp) {
				console.log(rsp, "图片选择呀")
				this.url = rsp.path; //更新头像方式一
				pathToBase64(rsp.path).then(base64 => {
					console.log(this.turl, "this.turlthis.turl")
					uni.request({
						url: 'https://dsx.cdzer.com/merchants/Video/uploadImage', //仅为示例，并非真实接口地址。
						data: {
							cover_image: base64
						},
						header: {
							'content-type': 'application/x-www-form-urlencoded',
						},
						method: 'POST',
						success: (res) => {
							console.log(res, "上传视频封面")
							this.zhenImg = res.data.data.image_url
							var data ={
								field_name:'headimgurl',
								field_data:this.zhenImg
							}
							this.$http.useben(data).then(res => {
								if (res.status == 200) {
									console.log(res, "保存资料")
									this.$hideLoading()
									uni.showToast({
										title: res.mess
									})
								} else {
									uni.showToast({
										title: res.mess,
										icon: 'none'
									})
								}
							})
						}
					});
				}).catch(error => {
					console.log(error)
				})
				//rsp.avatar.imgSrc = rsp.path; //更新头像方式二
			},
		}
	}
</script>

<style scoped lang="scss">
	.list {
		display: flex;
		flex-direction: column;
		padding: 30upx;
		justify-content: center;
		border-bottom: 2upx solid #EEEEEE;

		.list-z {
			display: flex;
			flex-direction: column;

			.tou {
				font-size: 36upx;
				color: 333333;
				font-weight: 550;
			}
		}

		view {
			padding-top: 5upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			color: #000;
		}
	}
</style>
